<?php
class Mysql{
	private $_dbs = array();
	private static $_self;
	public static function single(){
		if(self::$_self instanceof Mysql){
		}else{
			self::$_self = new Mysql;
		}
		return self::$_self;
	}
	private function __construct(){}
	public function getCon($name){
		$config = Config::single();
		$confname = $config->getDbConfig($name); 
		$key = md5($confname['host'].$confname['port'].$confname['user'],$confname['pwd'].$confname['dbname']);
		if(!isset($this->_dbs[$key])){
			$this->_dbs[$key] = mysql_connect($confname['host'],$confname['user'],$confname['pwd']);
			if($this->_dbs[$key]){
				if(mysql_select_db($confname['dbname'],$this->_dbs[$key])){
					mysql_query(sprintf("SET NAMES %s",$confname['charset']),$this->_dbs[$key]);
				}
			}
		}
		return $this->_dbs[$key];
	}
	
}
